package com.support.android.myapp3.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.support.android.myapp3.R;
import com.support.android.myapp3.adapter.FragmentAdapter;
import com.support.android.myapp3.adapter.MyPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class Tab2Fragment extends Fragment {
    private View view;
    private static Tab2Fragment fa;
    public static Tab2Fragment getInstance() {
        if (fa == null) {
            fa = new Tab2Fragment();
        }
        return fa;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view= inflater.inflate(R.layout.fragment_tablayout, container, false);


        ViewPager viewPager = (ViewPager) view.findViewById(R.id.viewpager);

        FragmentAdapter adapter = new FragmentAdapter(getActivity().getSupportFragmentManager());

        adapter.addFragment(new SelectedFragment(),"精选");
        adapter.addFragment(new SubscribeFragment(),"订阅");
        adapter.addFragment(new FinderFragment(),"发现");

        //将ViewPager与适配器关联
        viewPager.setAdapter(adapter);

        //TabLayout
        TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tablayout);

        //将ViewPager与TabLayout关联
        tabLayout.setupWithViewPager(viewPager);

        //设置指示器的颜色
        tabLayout.setSelectedTabIndicatorColor(Color.GREEN);


        return   view;
    }

}
